//
//  BKMyViewController.m
//  bestkeep
//
//  Created by windCould on 2016/11/3.
//  Copyright © 2016年 utouu. All rights reserved.
//

#import "BKMyViewController.h"
#import "BKMyCommon.h"
#import "BKUserHeadView.h"
#import "BKUserOrderInfoViewCell.h"
#import "BKUserInfoITTACell.h"
#import "BkCustomNavBarView.h"
#import "BkUserSettingController.h"
#import "BKMyUserFavorStoreController.h"
#import "BKUserUnitRequestAPI.h"
#import "BKUserRequestResultModel.h"
#import "BKUserPersonalInfoViewController.h"
#import "BKUserRealNameAuthController.h"
#import "BKMyOrderReuanGoogController.h"
#import "BK_my_ShippingAddressVC.h"
#import "BK_My_CupVC.h"
#import "BKUserLoginController.h"
#import "SystemMessageVC.h"
#import "Mediator+BKMy.h"
#import "BKMyOrderViewController.h"
#import "BKMyOrderGetDataFromNetWork.h"
#import "BKModifyUserPwdController.h"
#import "BKUserRealNameAuthReshultController.h"
#import "BKUserMyAccountController.h"
#import "BKUserRequestUrl.h"
#import "BKUserCustomerServerceController.h"
#import "BK_StoreOrder_VC.h"
#import "BK_StorePay_VC.h"

#import "AFNetworking.h"
#import "UTLogin.h"
#import "BKUserMyCouponController.h"
#import "BKRefreshGifHeader.h"

#define BKUserMainViewDefaultCellStyleID @"BKUserMainViewDefaultCellStyleID"
#define BkUserMainViewValue1CellStyleID  @"BkUserMainViewValue1CellStyleID"
#define BKUserAllOrderInfoCellStyleID    @"BKUserAllOrderInfoCellStyleID"

@interface BKMyViewController ()<UITableViewDelegate,UITableViewDataSource,BKUserHeadViewDelegate,BKUserOrderInfoViewCellDelegate,UINavigationControllerDelegate>

//布局
@property(nonatomic,strong)UITableView * mainTableView;
@property(nonatomic,strong)BKUserHeadView * headerView;
@property (nonatomic,strong)UIButton * settingBtn;
@property (nonatomic,strong)UIButton * messageBtn;
@property (nonatomic,strong)UIView * bageView;
@property (nonatomic,strong)BkCustomNavBarView * cusNavBar;

@property(nonatomic,strong)NSArray<SectionModel *>* sectionArr;
@property(nonatomic,strong)BKMyOrderStatusCount *statusCountModel;
@property (nonatomic,assign)CGFloat  viewAlpha;


@end

@implementation BKMyViewController

{
    BOOL isUTOUUPay;
    BOOL isUTOUUOrder;
}

- (void)viewDidLoad {
    [super viewDidLoad];

    self.edgesForExtendedLayout = UIRectEdgeNone;
    [self initializeComponent];
     _sectionArr = [self createDatas];
    NSDictionary * dict = [[Mediator sharedInstance]BKMyUserInfo];
    NSLog(@"%@",dict);
    self.viewAlpha = 0;
    self.navigationController.delegate = self;
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(haveNewsMessage) name:@"NSNotificationHaveNewNewMessage" object:nil];
}

-(void)setSectionArr:(NSArray<SectionModel *> *)sectionArr
{
    _sectionArr = sectionArr;
    [self.mainTableView reloadData];
}


-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self getUTOUUstatus];
    //判定用户是否登录，登录进行数据请求
    if (self.navigationController) {
        [self.navigationController setNavigationBarHidden:YES animated:animated];
    }
    [self updateData];
}

-(void)updateData
{
    if ([self islogin]) {
        
        [self getUserInfoWithLogin:YES];
        [self getUserLeverOfVip];
      //  [self getUnreadMessage];
      //  [self getUserOrderStususCount];//订单各个状态的数量;
    } else {
        self.statusCountModel  = nil;//用户登录退出后,将订单模型要清空;
        [self.mainTableView reloadData];
        [self getUserInfoWithLogin:NO];
        [self.mainTableView.mj_header endRefreshing];
    }
    //判断是否有新消息
    [self isHaveNewInform];
}

-(void)getUnreadMessage
{
    [[Mediator sharedInstance] getUnreadMessageNum];
}

-(void)haveNewsMessage
{
    if (![self islogin]) {
        
        return;
   }
    
   BKUserStatusInfo * userInfo = [BKUserStatusInfo currentUser];
    [userInfo.realm beginWriteTransaction];
    
     userInfo.unreadMessageNum = @"1";
    [userInfo.realm commitWriteTransaction];
    [self isHaveNewInform];
}


-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];

}

-(void)viewDidDisappear:(BOOL)animated
{
    [super viewDidAppear:animated];
}

-(void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    BOOL isHide = [viewController isKindOfClass:[self class]];
    if (isHide) {
        
         self.cusNavBar.alpha = self.viewAlpha;
        
    } else {
    
        self.cusNavBar.alpha = 1;
        [self.navigationController.navigationBar setTranslucent:YES];
    }
    
    [self.navigationController setNavigationBarHidden:isHide animated:YES];
}

 
#pragma mark =========================Function==================================

-(void)getUserInfoWithLogin:(BOOL)islogin
{
    if (islogin) {
        
        BKUserStatusInfo * userStatusInfo = [BKUserStatusInfo currentUser];
        _headerView.userLogoUrlStr = userStatusInfo.photo;
        _headerView.userNickName = userStatusInfo.nickName;
        _headerView.userLevel = userStatusInfo.levelNum;
    } else {
    
        _headerView.userLogoUrlStr = nil;
        _headerView.userNickName = @"登录／注册";
        _headerView.userLevel = @"";
    }
    self.sectionArr = [self createDatas];
 }

-(void)pushToTargetController:(UIViewController *)targetVC animal:(BOOL)animal
{
    //先判断是否登录
    BOOL  isLogin = [BKMyCommon userIsLoginWithInController:self];
    if (isLogin) {
        //跳转
        targetVC.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:targetVC animated:animal];
    }
}

-(BOOL)islogin
{
    BKUserStatusInfo * userStatusInfo = [BKUserStatusInfo currentUser];
    return userStatusInfo.isLogin;
}

#pragma mark =========================NetRequest=======================

-(void)getUserLeverOfVip
{
    __weak typeof(self) weaKSelf = self;
    [BKUserUnitRequestAPI getUserLeverOfVipWithResultBlock:^(id obj, NSError *error) {
    
        [weaKSelf.mainTableView.mj_header endRefreshing];
        if (error) {
           
            if (![error.localizedDescription isEqualToString:@"未能读取数据，因为它的格式不正确。"]) {
                
                 //[HUD showErrorMessage:error.localizedDescription];
            }
            NSLog(@"%@",error.localizedDescription);
            return ;
         }
        BKUserRequestResultModel * result = obj;
        if ([result.success isEqualToString:@"1"]) {
           
            NSLog(@"个人VIP信息请求成功");
            [self getUserOrderStususCount];//订单各个状态的数量;
            [self getUserInfoWithLogin:YES];
        } else {
        
            NSLog(@"%@",result.msg);
           // [HUD showErrorMessage:result.msg];
        }

    }];
}
-(void)getUserOrderStususCount{
  
    
    __weak typeof(self) weakSelf = self;
    [BKMyOrderGetDataFromNetWork GetOrderStausSuccess:^(id obj) {
       
        [self getUnreadMessage];
        [weakSelf.mainTableView.mj_header endRefreshing];
        self.statusCountModel = obj;
        [self.mainTableView reloadData];
        
    } failure:^(NSError *error) {
         [weakSelf.mainTableView.mj_header endRefreshing];
        
    }];
}

#pragma mark ============ BKUserHeadViewDelegate ======================
-(void)bKUserHeaderView:(BKUserHeadView *)userHeadView clickLogoBtn:(UIButton *)btn
{
    BKUserPersonalInfoViewController * infoVc = [[BKUserPersonalInfoViewController alloc]init];
    [self pushToTargetController:infoVc animal:YES];
    
}

#pragma mark ============= 查看订单 =====================================
-(void)goToViewAllOreders
{//先判断是否登录
   
    BOOL  isLogin = [BKMyCommon userIsLoginWithInController:self];
    if (isLogin) {
    [self PushMyOrderVc:@"0"];//所有订单
    }
}

-(void)bKUserOrderInfoViewCell:(BKUserOrderInfoViewCell *)bKUserOrderInfoViewCell  goToAllOrders:(orderStatus)status
{
    BOOL  isLogin = [BKMyCommon userIsLoginWithInController:self];
    if (isLogin) {
        [self PushMyOrderVc:@"1"];//待付款
    }
}

-(void)bKUserOrderInfoViewCell:(BKUserOrderInfoViewCell *)bKUserOrderInfoViewCell  goToWaitToPayOrders:(orderStatus)status
{
    BOOL  isLogin = [BKMyCommon userIsLoginWithInController:self];
    if (isLogin) {
        [self PushMyOrderVc:@"2"];//待发货
    }
 
}

-(void)bKUserOrderInfoViewCell:(BKUserOrderInfoViewCell *)bKUserOrderInfoViewCell  goToWaitToReceviewOrders:(orderStatus)status
{
    BOOL  isLogin = [BKMyCommon userIsLoginWithInController:self];
    if (isLogin) {
        [self PushMyOrderVc:@"3"];//待收货;
    }
    }

-(void)bKUserOrderInfoViewCell:(BKUserOrderInfoViewCell *)bKUserOrderInfoViewCell  goToWaitToEvlotionOrders:(orderStatus)status
{
    BOOL  isLogin = [BKMyCommon userIsLoginWithInController:self];
    if (isLogin) {
    [self PushMyOrderVc:@"4"];//待评价
    }
  
}
//退换货;
-(void)bKUserOrderInfoViewCell:(BKUserOrderInfoViewCell *)bKUserOrderInfoViewCell  goToReturnAndExchangerders:(orderStatus)status
{
    BOOL  isLogin = [BKMyCommon userIsLoginWithInController:self];
    if (isLogin) {
        BKMyOrderReuanGoogController *con = [BKMyOrderReuanGoogController new];
        [self.navigationController pushViewController:con animated:YES];
    }
}

-(void)PushMyOrderVc:(NSString*)str{
    
    BKMyOrderViewController * con =[[BKMyOrderViewController alloc]init];
    con.str_type=str;
    con.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:con animated:YES];
    
}
#pragma mark ============ mainTableView的cell的点击方法 ===================


-(void)goToMembership
{
    BOOL  isLogin = [BKMyCommon userIsLoginWithInController:self];
   
    if (isLogin) {
        
        NSString *urlStr = [UserPassPortStr stringByAppendingString:AccountLoginUrlStr];
        NSString *tgt = [[Mediator sharedInstance]BKMyUserInfo][BKMyUserGetTGTKey];
        NSString *stUrl = [NSString stringWithFormat:@"%@/%@", urlStr, tgt];
        NSString *value = [UserWebStr stringByAppendingString:@"profile/vip"];
        NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:value,@"service", nil];
        NSDictionary *headDic = [UTLogin getSTHeadDictionary:dic params:dic strurl:stUrl];
        AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
        manager.requestSerializer = [AFHTTPRequestSerializer serializer];
        manager.responseSerializer = [AFHTTPResponseSerializer serializer];
        manager.securityPolicy.allowInvalidCertificates = YES;
        manager.securityPolicy.validatesDomainName = NO;
        for (NSString *key in [headDic allKeys]) {
            NSString *value = [headDic objectForKey:key];
            [manager.requestSerializer setValue:value forHTTPHeaderField:key];
        }
        [BKIndicationView showInView:self.view];
        [manager POST:stUrl parameters:dic progress:^(NSProgress * _Nonnull uploadProgress) {
            
        } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            [BKIndicationView dismiss];
            NSLog(@"%@", responseObject);
            NSString *st = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
            
            BKUserMyCouponController *coupon = [[BKUserMyCouponController alloc] init];
            coupon.requestUrl = [NSString stringWithFormat:@"%@%@%@",UserWebStr,@"profile/vip?ticket=",st];
            [self.navigationController pushViewController:coupon animated:YES];
            
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            [BKIndicationView dismiss];
            NSLog(@"Error: %@", error);
            if (error.code==502) {
                [HUD showErrorMessage:@"服务器开小差了，请稍后再试！"];
            }else{
                [HUD showErrorMessage:error.localizedDescription];
            }
        }];
    }
    
}

-(void)goToAccount
{
    BKUserMyAccountController * accountVC = [[BKUserMyAccountController alloc]init];
    [self pushToTargetController:accountVC animal:YES];
}

-(void)goToRealName
{
    
    BOOL  isLogin = [BKMyCommon userIsLoginWithInController:self];
    
    if (isLogin) {
        
        [BKIndicationView showInView:self.view];
        [BKUserUnitRequestAPI getUserAuthRealNameDeatailWithCompleteBlock:^(id obj, NSError *error) {
            [BKIndicationView dismiss];
            if (obj) {
                
                NSDictionary * dict = obj;
                NSNumber * isSuccess = dict[@"success"];
                NSInteger  numstr = [isSuccess integerValue];
                if (numstr == 1) {
                    
                    BKUserRealNameAuthReshultController * resultRealNameVc = [[BKUserRealNameAuthReshultController alloc]init];
                    NSDictionary *dataDic = [obj objectForKey:@"data"];
                    
                    resultRealNameVc.type = [[obj objectForKey:@"data"] objectForKey:@"realAuthStatus"];
                    
                    if (![resultRealNameVc.type integerValue]) {
                        
                        BKUserRealNameAuthController * realNameVc = [[BKUserRealNameAuthController alloc]init];
                        [self pushToTargetController:realNameVc animal:YES];
                    } else {
                        
                        resultRealNameVc.realName = [dataDic objectForKey:@"realName"];
                        resultRealNameVc.realPersonalId = [dataDic objectForKey:@"certypeNumber"];
                        resultRealNameVc.rejectReason = [dataDic objectForKey:@"reject"];
                        resultRealNameVc.realAuthStatusStr = [dataDic objectForKey:@"realAuthStatusStr"];
                        [self pushToTargetController:resultRealNameVc animal:YES];
                    }
                } else {
                    
                    [HUD showErrorMessage:dict[@"msg"]];
                    
                }
                
            } else {
                
                if (error.code==502) {
                    [HUD showErrorMessage:@"服务器开小差了，请稍后再试！"];
                }else{
                    [HUD showErrorMessage:error.localizedDescription];
                }
            }
            
        }];
    }
    
}


-(void)goToCoupon
{
    BK_My_CupVC *couponVC = [[BK_My_CupVC alloc] init];
    couponVC.hidesBottomBarWhenPushed = YES;
    [self pushToTargetController:couponVC animal:YES];
//    BK_my_CouponVC *couponVC = [[BK_my_CouponVC alloc] init];
//    couponVC.hidesBottomBarWhenPushed = YES;
//    [self pushToTargetController:couponVC animal:YES];
}

-(void)goToViewMyFavorite
{

    BKMyUserFavorStoreController * favorVc = [[BKMyUserFavorStoreController alloc]init];
    [self pushToTargetController:favorVc animal:YES];
}

-(void)goToAddress
{
    BK_my_ShippingAddressVC *addressVC = [[BK_my_ShippingAddressVC alloc] init];
    [self pushToTargetController:addressVC animal:YES];
}

-(void)goToQuestion
{
    
    BKUserCustomerServerceController * webService = [[BKUserCustomerServerceController alloc] init];
    webService.urlStr = [UserWebStr stringByAppendingString:UserAskQuestionStr];
    webService.webViewTitle = BKMyLocalizedString(@"BKUserMyQuestion");
    webService.str_webType = @"1";
    webService.isFirst = YES;
    [self pushToTargetController:webService animal:YES];

}
//小店订单跳转；
- (void)goToStoreOrders {
    
    BK_StoreOrder_VC *storeOrder_VC = [[BK_StoreOrder_VC alloc] init];
    [self pushToTargetController:storeOrder_VC animal:YES];
    
}
//跳转小店支付
- (void)gotoStorePay_VC {
    
    BK_StorePay_VC *storePayVC = [[BK_StorePay_VC alloc] init];
    [self pushToTargetController:storePayVC animal:YES];
    
}
#pragma mark ============ Navigationbar上的按钮的点击事件 ===================

-(void)systemMessage
{
    SystemMessageVC *systemMessage = [[SystemMessageVC alloc] init];
    systemMessage.hidesBottomBarWhenPushed = YES;
    [self pushToTargetController:systemMessage animal:YES];
    
}
//判断是否有新消息 选择是否显示有红点
-(void)isHaveNewInform
{
    BKUserStatusInfo * userInfo = [BKUserStatusInfo currentUser];
    
    if (![userInfo.unreadMessageNum isEqualToString:@""]) {
        
        self.bageView.hidden = NO;
    } else {
        self.bageView.hidden = YES;
    }
}

-(void)systemSetting
{
    BkUserSettingController * settingVc = [[BkUserSettingController alloc]init];
    settingVc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:settingVc animated:YES];

}

#pragma mark ============= mainTableViewDelegate ========================

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    SectionModel * sect = _sectionArr[section];
    return sect.cells.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    SectionModel* sect = _sectionArr[indexPath.section];
    CellModel * item = sect.cells[indexPath.row];
  
    return  item.height;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return _sectionArr.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    SectionModel * sect = _sectionArr[section];
    return sect.headerhHeight;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    SectionModel * sect = _sectionArr[section];
    return sect.footerHeight;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    SectionModel* sect = _sectionArr[indexPath.section];
    CellModel * item = sect.cells[indexPath.row];
    
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:item.reuseIdentifier];
    if (!cell) {
         NSString *str = NSStringFromClass([BKUserOrderInfoViewCell class]);
            cell = [[NSClassFromString(item.className) alloc]initWithStyle:item.style reuseIdentifier:item.reuseIdentifier];
          if ([item.className isEqualToString:str]) {
           
              BKUserOrderInfoViewCell *Cell = (BKUserOrderInfoViewCell *)cell;
              Cell.orderStatusDelegate = self;
              cell = cell;
        }
    }
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.separatorInset = UIEdgeInsetsMake(0, -10, 0, 0);
    return cell;
}

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    SectionModel * sect = _sectionArr[indexPath.section];
    CellModel * item = sect.cells[indexPath.row];
    
    if ([cell respondsToSelector:@selector(fillData:)]) {
        
        NSString *str = NSStringFromClass([BKUserOrderInfoViewCell class]);
        if ([item.className isEqualToString:str]) {
        [cell performSelector:@selector(fillData:) withObject:self.statusCountModel];
    }
        else{
            
            [cell performSelector:@selector(fillData:) withObject:item];
        }

    }

}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    SectionModel * sect = _sectionArr[indexPath.section];
    CellModel * item = sect.cells[indexPath.row];
    
    NSString * selString = item.selectorString;
    if (selString) {
        
        SEL selec = NSSelectorFromString(selString);
        if ([self respondsToSelector:selec]) {
        
#pragma clang diagnostic push
#pragma clang diagnostic ignored"-Warc-performSelector-leaks"
            
            [self performSelector:selec withObject:nil];
        }
    }

}

#pragma mark ========================视图的scrowViewDelegate==============================

-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
        CGFloat offsetY = scrollView.contentOffset.y;
        CGFloat percent  = offsetY / 64;
    
        if(percent >= 0.5)
        {
            if (percent >=1) {
                
                percent = 0.99;
            }
            [UIView animateWithDuration:0.2 animations:^{
        
                self.cusNavBar.alpha=percent;
                self.viewAlpha = percent;
            }];
            
        } else {
            
            self.cusNavBar.alpha=0;
            self.viewAlpha = 0;
        }
}

- (void)getUTOUUstatus {
    
    if (!isUTOUUOrder) {
        if ([BKMyAction readStringWithUTOUUOrderStatus]) {
            isUTOUUOrder = YES;
        }
    }
    if (!isUTOUUPay) {
        if ([BKMyAction readStringWithUTOUUPayStatus]) {
            isUTOUUPay = YES;
        }
    }
}

#pragma mark ===========================视图布局============================================
-(void)initializeComponent {
    
    self.view.backgroundColor = ThemeBackgroundColor;
    
    _mainTableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
    _mainTableView.dataSource = self;
    _mainTableView.delegate= self;
    _mainTableView.showsVerticalScrollIndicator = NO;
    _headerView = [[BKUserHeadView alloc]initWithFrame:CGRectMake(0, 0, SCREENWIDTH, 200)];
    _headerView.headerViewDelegate = self;
    _mainTableView.tableHeaderView = _headerView;
    _mainTableView.tableFooterView = [[UIView alloc]init];
    _mainTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:_mainTableView];
    
    
    //设置自定义导航栏
    [self setUpCustomNav];
    
    [self layoutViews];
    
}

-(void)refreshData
{
    [self updateData];
}


-(void)setUpCustomNav
{
    
    BkCustomNavBarView * navBarView =[[BkCustomNavBarView alloc]initWithFrame:CGRectMake(0, 0, SCREENWIDTH, 64)];
    navBarView.alpha = 0;
    self.cusNavBar = navBarView;
    navBarView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:navBarView];
    
    UIButton *settingButton= [UIButton buttonWithType:UIButtonTypeCustom];
    self.settingBtn = settingButton;
    [settingButton addTarget:self action:@selector(systemSetting) forControlEvents:UIControlEventTouchUpInside];
    [settingButton setImage:[UIImage imageNamed:@"BK_My_new设置"] forState:UIControlStateNormal];
    [settingButton setImage:[UIImage imageNamed:@"BK_My_new设置"] forState:UIControlStateHighlighted];
    [settingButton sizeToFit];
    
    UIButton *messageButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.messageBtn = messageButton;
    [messageButton addTarget:self action:@selector(systemMessage) forControlEvents:UIControlEventTouchUpInside];
    [messageButton setImage:[UIImage imageNamed:@"BK_My_消息中心"] forState:UIControlStateNormal];
    [messageButton setImage:[UIImage imageNamed:@"BK_My_消息中心"] forState:UIControlStateHighlighted];
    [messageButton sizeToFit];
    
    UIView * badgeView = [[UIView alloc]initWithFrame:CGRectZero];
    self.bageView = badgeView;
    badgeView.hidden = YES;
    badgeView.layer.cornerRadius = 3;
    badgeView.layer.masksToBounds = YES;
    badgeView.backgroundColor = [UIColor redColor];
    [messageButton addSubview:badgeView];
    
    [self.view addSubview:settingButton];
    [self.view addSubview:messageButton];
    
}


-(void)layoutViews{
    
    [self.cusNavBar mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.view.mas_left);
        make.right.mas_equalTo(self.view.mas_right);
        make.top.mas_equalTo(self.view.mas_top);
        make.height.mas_equalTo(64);
    }];
    
    [self.settingBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.view.mas_right).offset(-ApplicationNavigationBarBackGauge-8);
        make.top.mas_equalTo(self.view.mas_top).offset(28);
        make.height.mas_equalTo(26);
        make.width.mas_equalTo(26);
    }];
    
    [self.messageBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(self.settingBtn.mas_left).offset(-10);
        make.top.mas_equalTo(self.settingBtn.mas_top);
        make.height.mas_equalTo(26);
        make.width.mas_equalTo(26);
        
    }];

    [self.bageView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.mas_equalTo(self.messageBtn.mas_top).offset(6);
        make.centerX.mas_equalTo(self.messageBtn.mas_right).offset(-3);
        make.size.mas_equalTo(CGSizeMake(6, 6));
    }];
    
    [_mainTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.view.mas_top).offset(0);
        make.left.mas_equalTo(self.view.mas_left).offset(0);
        make.right.mas_equalTo(self.view.mas_right).offset(0);
        make.bottom.mas_equalTo(self.view.mas_bottom).offset(0);
        
    }];
    
    _headerView.frame = CGRectMake(0, 0,SCREENWIDTH, 200);
    
}

-(NSArray<SectionModel*>*)createDatas {
    
    //我的订单；
    CellModel *myOrder = [CellModel cellModelWithTitle:BKMyLocalizedString(@"BKUserAllOrder") subTitle:BKMyLocalizedString(@"BKUserViewAllOrders") image:@"icon_normal_dingdan" sel:@"goToViewAllOreders"];
    myOrder.height = 45;
    myOrder.className = NSStringFromClass([BKUserInfoITTACell class]);
    myOrder.style = UITableViewCellStyleValue1;
    myOrder.reuseIdentifier = BKUserInfoITTACellIdentify;
    myOrder.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    myOrder.isNewsImgV = YES;
    myOrder.isShowBottomLine = YES;
    
    CellModel * orderStatus = [[CellModel alloc]init];
    orderStatus.height = 69;
    orderStatus.className = NSStringFromClass([BKUserOrderInfoViewCell class]);
    orderStatus.reuseIdentifier = BKUserAllOrderInfoCellStyleID;
    orderStatus.accessoryType = UITableViewCellAccessoryNone;
    
    SectionModel *section0 = [SectionModel sectionModelWithTitle:nil cells:@[myOrder,orderStatus]];
    section0.headerhHeight = 10;
    section0.footerHeight = 0.1;
    
    //小店订单
    CellModel *storeOrders = [CellModel cellModelWithTitle:BKMyLocalizedString(@"BKUserStoreOrders") subTitle:nil image:@"BK_My_StoreOrders" sel:@"goToStoreOrders"];
    storeOrders.height = 45;
    storeOrders.className = NSStringFromClass([BKUserInfoITTACell class]);
    storeOrders.isNewsImgV = isUTOUUOrder;
    storeOrders.isShowBottomLine = NO;
    storeOrders.reuseIdentifier = BKUserInfoITTACellIdentify;
    storeOrders.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    //支付码
    CellModel *payFromBarcode = [CellModel cellModelWithTitle:BKMyLocalizedString(@"BKUserPayFromBarcode") subTitle:nil image:@"BK_My_二维码" sel:@"gotoStorePay_VC"];
    payFromBarcode.height = 45;
    payFromBarcode.className = NSStringFromClass([BKUserInfoITTACell class]);
    payFromBarcode.reuseIdentifier = BKUserInfoITTACellIdentify;
    payFromBarcode.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    payFromBarcode.isShowBottomLine = YES;

    SectionModel *section1 = [SectionModel sectionModelWithTitle:nil cells:@[payFromBarcode, storeOrders]];
    section1.headerhHeight = 10;
    section1.footerHeight = 0.1;
    payFromBarcode.isNewsImgV = isUTOUUPay;
    
    //我的会员卡
    CellModel *membership = [CellModel cellModelWithTitle:BKMyLocalizedString(@"BKUserMyMembership") subTitle:nil image:@"icon_normal_wodehuiyuanka" sel:@"goToMembership"];
    membership.height = 45;
    membership.className = NSStringFromClass([BKUserInfoITTACell class]);
    membership.reuseIdentifier = BKUserInfoITTACellIdentify;
    membership.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    membership.isNewsImgV = YES;
    membership.isShowBottomLine = YES;
    
    //我的账号
    CellModel *account = [CellModel cellModelWithTitle:BKMyLocalizedString(@"BKUserMyAccount") subTitle:nil image:@"icon_normal_wodezhanghu" sel:@"goToAccount"];
    account.height = 45;
    account.className = NSStringFromClass([BKUserInfoITTACell class]);
    account.reuseIdentifier = BKUserInfoITTACellIdentify;
    account.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    account.isNewsImgV = YES;
    account.isShowBottomLine = YES;
    BKUserStatusInfo * statusInfo = [BKUserStatusInfo currentUser];
    
    //实名认证
    NSString * selectorStr;
    selectorStr = @"goToRealName";
    CellModel *realName = [CellModel cellModelWithTitle:BKMyLocalizedString(@"BKUserMyRealName") subTitle: statusInfo.realAuthStatus image:@"icon_normal_shimingrenzheng" sel:selectorStr];
    realName.height = 45;
    realName.isNewsImgV = YES;
    realName.isShowBottomLine = YES;
    realName.style = UITableViewCellStyleValue1;
    realName.className = NSStringFromClass([BKUserInfoITTACell class]);
    realName.reuseIdentifier = BKUserInfoITTACellIdentify;
    realName.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    //我的优惠券
    CellModel *coupon = [CellModel cellModelWithTitle:BKMyLocalizedString(@"BKUserMyCoupon") subTitle:nil image:@"icon_normal_youhuiquan" sel:@"goToCoupon"];
    coupon.height = 45;
    coupon.className = NSStringFromClass([BKUserInfoITTACell class]);
    coupon.reuseIdentifier = BKUserInfoITTACellIdentify;
    coupon.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    coupon.isNewsImgV = YES;
    coupon.isShowBottomLine = NO;
    
    SectionModel *section2 = [SectionModel sectionModelWithTitle:nil cells:@[membership, account, realName, coupon]];
    section2.headerhHeight = 10;
    section2.footerHeight = 0.1;
    
    //我的收藏
    CellModel *myFavor = [CellModel cellModelWithTitle:BKMyLocalizedString(@"BKUserMyFavorite") subTitle:nil image:@"icon_normal_shoucang" sel:@"goToViewMyFavorite"];
    myFavor.height = 45;
    myFavor.className = NSStringFromClass([BKUserInfoITTACell class]);
    myFavor.reuseIdentifier = BKUserInfoITTACellIdentify;
    myFavor.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    myFavor.isNewsImgV = YES;
    myFavor.isShowBottomLine = YES;
    
    //收货地址
    CellModel *address = [CellModel cellModelWithTitle:BKMyLocalizedString(@"BKUserMyAddress") subTitle:nil image:@"icon_normal_shouhuodizhi" sel:@"goToAddress"];
    address.height = 45;
    address.className = NSStringFromClass([BKUserInfoITTACell class]);
    address.reuseIdentifier = BKUserInfoITTACellIdentify;
    address.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    address.isNewsImgV = YES;
    address.isShowBottomLine = NO;
    
    SectionModel *section3 = [SectionModel sectionModelWithTitle:nil cells:@[myFavor,address]];
    section3.headerhHeight = 10;
    section3.footerHeight = 0.1;
    
    //问题咨询
    CellModel *question = [CellModel cellModelWithTitle:BKMyLocalizedString(@"BKUserMyQuestion") subTitle:nil image:@"icon_normal_wodezixun" sel:@"goToQuestion"];
    question.height = 45;
    question.className = NSStringFromClass([BKUserInfoITTACell class]);
    question.reuseIdentifier = BKUserInfoITTACellIdentify;
    question.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    question.isNewsImgV = YES;
    question.isShowBottomLine = NO;
    
    SectionModel *section4 = [SectionModel sectionModelWithTitle:nil cells:@[question]];
    section4.headerhHeight = 10;
    section4.footerHeight = 10;
    
    return @[section0,section1,section2,section3,section4];
}


@end
